const getDefaultState = () => {
  return {
    token: '',
    userInfo: {},
    business_id: 1,
    origin: 'h5', // 访问来源
    queryParams: null
  }
}

const state = getDefaultState()

const mutations = {
  SET_TOKEN: (state, token) => {
    state.token = token
  },
  SET_USER_INFO: (state, userInfo) =>{
    state.userInfo = userInfo;
  },
  SET_BUSSINESS_ID: (state, business_id) =>{
    state.business_id = business_id;
  },
  SET_ORIGIN: (state, origin) => {
    state.origin = origin
  },
  SET_QUERY_PARAMS: (state, queryParams) => {
    state.queryParams = queryParams
  },
}

const actions = {
  // 设置token
  async setToken ({ commit }, token) {
    commit('SET_TOKEN', token);
  },
  // 设置商户id
  async setBusinessId ({ commit }, business_id) {
    console.log(business_id)
    commit('SET_BUSSINESS_ID', business_id);
  },
  // 设置商户id
  async setOrigin ({ commit }, origin) {
    console.log(origin)
    commit('SET_ORIGIN', origin);
  },
  // 设置链接参数
  async setQueryParams ({ commit }, queryParams) {
    console.log(queryParams)
    commit('SET_QUERY_PARAMS', queryParams);
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

